<template>
  <!--  table-->
  <SuperTable ref="superTableRef" search pager border align="center" :columns="columns" :data-request="fetchData" :export-config="{}" header-title="操作记录" />
  <!--  modal-->
  <DraggableModal v-model:visible="showModal" title="日志详情" :footer="null" width="1200px">
    <component :is="currentModal" :data="modal.currentData" />
  </DraggableModal>
</template>

<script setup lang="ts">
import SuperTable from '@/framework/components/core/super-table/super-table.vue';
import { VxeGridPropTypes } from 'vxe-table';
import type { TableColumnItem } from './columns';
import { baseColumns } from './columns';
import { DraggableModal } from '@/framework/components/core/draggable-modal';
import { reactive, ref, shallowRef } from 'vue';
import { journalSearch, journalShow } from '@/modules/smart-reminders/api/index';
import DisposeModal from '@/modules/smart-reminders/pages/record-of-operations/components/dispose-modal/dispose-modal.vue';
import MoveModal from '@/modules/smart-reminders/pages/record-of-operations/components/move-modal/move-modal.vue';
import OutboundModal from '@/modules/smart-reminders/pages/record-of-operations/components/outbound-modal/outbound-modal.vue';
import StorageModal from '@/modules/smart-reminders/pages/record-of-operations/components/storage-modal/storage-modal.vue';
import VerificationModal from '@/modules/smart-reminders/pages/record-of-operations/components/verification-modal/verification-modal.vue';

/**
 * const
 */
const modalData = {
  // 1001: '暂存样本入库', // 废弃
  // 1002: '保藏样本入库', // 废弃
  1003: OutboundModal,
  1004: DisposeModal,
  1005: StorageModal,
  1006: MoveModal,
  1008: VerificationModal,
};

/**
 * modal
 */
const showModal = ref(false);
const currentModal = shallowRef();
const modal: {
  currentData: any;
} = reactive({
  currentData: {},
});

/**
 * table
 */
const superTableRef = ref<InstanceType<typeof SuperTable>>();
const columns: TableColumnItem[] = [
  ...baseColumns,
  {
    title: '操作',
    field: '$action',
    hideInSearch: true,
    align: 'center',
    fixed: 'right',
    width: 100,
    actions: ({ row }) => [
      {
        label: '查看',
        onClick: async () => {
          currentModal.value = modalData[row.optCode];
          const res = await journalShow(row.id);
          modal.currentData = res.result;
          showModal.value = true;
        },
      },
    ],
  },
];
const fetchData = async (ori: VxeGridPropTypes.ProxyAjaxQueryParams) => {
  let data = superTableRef.value?.getFormModel();
  let params = {
    pageSize: ori.page.pageSize,
    pageNum: ori.page.currentPage,
    orderBy: [
      {
        field: 'id',
        order: 'desc',
      },
    ],
    ...data,
    notInOptCode: '1007', // 过滤一些操作码
  };
  data.createTimeBtw ? (params.createTimeBtw = data.createTimeBtw.join() + ' 23:59:59') : delete params.createTimeBtw;
  let res = await journalSearch(params);
  return res.result;
  // return {
  //   data: [{}, {}, {}],
  //   pageIndex: 1,
  //   pageSize: 10,
  //   total: 100,
  // };
};
// const refreshTableFn = () => {
//   superTableRef.value?.refreshTable();
// };
</script>

<style scoped lang="less"></style>
